package java69.work716;

import java.util.Scanner;

public class Book2 {
    private String title;
    private String auther;
    private String press;
    private double price;

    static Book2[] book = new Book2[]{
            new Book2("小小小", "小小", "科海出版社", 22.0),
            new Book2("大大大", "大大", "科海出版社", 70.0),
            new Book2("中中中", "中中", "科海出版社", 34.5),
    };

    public String getTitle() {
        return title;
    }

    public String getAuther() {
        return auther;
    }

    public String getPress() {
        return press;
    }

    public void setPress(String press) {
        this.press = press;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        if (price < 10) {
            System.out.println("出售价格必须大于10元");
        } else {
            this.price = price;
        }
    }

    public Book2() {
    }

    public Book2(String title, String auther, String press, double price) {
        this.auther = auther;
        this.press = press;
        this.price = price;
        this.title = title;
    }

    /**
     * 信息介绍
     */
    public void showBookInfo() {
        String str = "序号" + "\t\t\t\t" + "书名" + "\t\t\t\t" + "作者" + "\t\t\t\t" + "出版社" + "\t\t\t\t" + "价格" + "\n";
        for (int i = 0; i < book.length; i++) {
            str = str + i + "\t\t\t\t" + book[i].title + "\t\t\t" + book[i].auther + "\t\t\t\t" + book[i].press + "\t\t\t" + book[i].price + "\n";
        }
        System.out.println(str);
    }

    /**
     * 修改书记信息
     */
    public void changeBookInfo() {
        Scanner sc = new Scanner(System.in);
        String name;
        double price;
        int num = 0;
        boolean isExit = false;
        do{
            System.out.println("请输入书序号:");
            int i = sc.nextInt();
            if (i < book.length && i >= 0) {
                System.out.println("请选择操作:");
                System.out.println("1.修改价格");
                System.out.println("2.修该出版社");
                System.out.println("3.修改所有");
                System.out.println("4.退出");
                int j = sc.nextInt();
                switch (j) {
                    case 1:
                        System.out.println("请输入新价格：");
                        book[i].setPrice(sc.nextDouble());
                        break;
                    case 2:
                        System.out.println("请输入新出版社：");
                        book[i].setPress(sc.next());
                        break;
                    case 3:
                        System.out.println("请输入新价格：");
                        book[i].setPrice(sc.nextDouble());
                        System.out.println("请输入新出版社：");
                        book[i].setPress(sc.next());
                        break;
                    default:
                        System.out.println("请输入正确操作！");
                        break;
                }
                if (isExit){
                    break;
                }else {
                    System.out.println("输入0返回菜单，请输入：");
                    num = sc.nextInt();
                }
            } else {
                System.out.println("请输入正确书序号");
            }
        }while (num ==0);

    }
}


